package com.hospital.controller;

import com.hospital.domain.pojo.Orders;
import com.hospital.domain.utils.Result;
import com.hospital.service.OrdersService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/orders")
public class OrdersController {

    private final OrdersService ordersService;

    // 管理端/医生端：查询全部订单（可按支付状态过滤）
    @GetMapping("/all")
    public Result<List<Orders>> all(@RequestParam(value = "status", required = false) Integer status){
        return ordersService.listAll(status);
    }

    // 患者端：查询本人订单
    @GetMapping("/patient/{pId}")
    public Result<List<Orders>> byPatient(@PathVariable Integer pId){
        return ordersService.listByPatient(pId);
    }

    // 患者端支付：点击即视为支付成功
    @PostMapping("/pay/{orderId}")
    public Result<Void> pay(@PathVariable Integer orderId){
        return ordersService.pay(orderId);
    }

    // 医生端退款：点击即视为退款成功
    @PostMapping("/refund/{orderId}")
    public Result<Void> refund(@PathVariable Integer orderId){
        return ordersService.refund(orderId);
    }
}

